package com.xssq.config;

import com.xssq.service.WebSocketServer;
import com.xssq.utils.webSocket.WebSocketService;
import com.xssq.utils.webSocket.WebSocketServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

import java.util.concurrent.ConcurrentHashMap;

/**
 * WebSocket配置
 * @author xssq
 * @version 1.0.0
 * @date 2023/09/02 08:52:26
 * @saying 你可以不会但你必须得知道
 */
@Configuration
public class WebSocketContext {

    /**
     * WebSocket服务
     * @return {@code ServerEndpointExporter}
     */
    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }

    /**
     * 给WebSocket设置服务
     *
     * @param webSocketService
     */
    @Autowired
    public void setService(WebSocketService webSocketService) {
        WebSocketServer.webSocketService = webSocketService;
        WebSocketServer.sessionMap = new ConcurrentHashMap<>();
    }

}
